home
diamond Go Premium
Data Engineering Path  ·  Airflow
Apache Airflow Logo

Common Pitfalls & How to Avoid Them

⚠️ Mistakes Every Airflow Developer Makes (And How to Fix Them)

Pitfall 1: Processing Data in Workers

# ❌ BAD — Worker runs out of memory
@task()
def process():
    df = pd.read_parquet("s3://bucket/100gb_file.parquet")
    result = df.groupby("category").agg({"amount": "sum"})
    result.to_parquet("s3://bucket/output.parquet")

# ✅ GOOD — Delegate to Spark
@task()
def process():
    spark_submit("--class com.company.Transform s3://jars/transform.jar")

Pitfall 2: Top-Level Code in DAG Files

# ❌ BAD — This runs every time the scheduler parses the file!
import requests
response = requests.get("https://api.example.com/config")  # Called every 30 seconds!
config = response.json()

with DAG(...) as dag:
    ...

# ✅ GOOD — Move to inside a task
@task()
def get_config():
    import requests
    response = requests.get("https://api.example.com/config")
    return response.json()

Pitfall 3: Huge XCom Values

# ❌ BAD — Pushing 50 MB DataFrame to XCom
@task()
def extract():
    return pd.read_csv("huge_file.csv").to_dict()  # Stored in metadata DB!

# ✅ GOOD — Store data externally, pass reference
@task()
def extract():
    df = pd.read_csv("huge_file.csv")
    path = "s3://staging/extracted_data.parquet"
    df.to_parquet(path)
    return {"path": path, "rows": len(df)}  # Only metadata in XCom

Pitfall 4: No Catchup=False

# ❌ BAD — start date is 2020, no catchup control
with DAG("my_dag", schedule="@hourly", start_date=datetime(2020, 1, 1)):
    # Airflow creates 35,000+ DAG Runs!

# ✅ GOOD — Explicit catchup=False
with DAG("my_dag", schedule="@hourly", start_date=datetime(2024, 1, 1), catchup=False):
    # Only creates runs from now onwards

Pitfall 5: Hardcoded Secrets

# ❌ BAD — Credentials in code (visible in source control!)
hook = PostgresHook(host="db.company.com", login="admin", password="s3cr3t!")

# ✅ GOOD — Use Airflow Connections
hook = PostgresHook(postgres_conn_id="production_warehouse")
# Credentials stored encrypted in Airflow metadata DB

Pitfall 6: Ignoring UI Error Diagnostics & Failed Task Overview

When complex DAGs fail in production, do not try to read unstructured scheduler logs from terminal. Instead, always use the Web UI's Grid Overview with quick links to failed tasks to instantly triage root causes and monitor pipeline status:

Airflow Web UI — Complex DAG Overview with Failed Tasks

📘 See Also
For a comprehensive list of best practices, refer to the official Airflow documentation: Best Practices Guide
lock

This content is reserved for Premium Members.

Upgrade to Premium

Entity Details

Create New Item

help

Submit Technical Query

Have a question or run into an issue? Describe it below, upload an optional screenshot, and our engineering team will answer it!

image Attach image (optional)

Submit Feedback

build Free Developer Utility Free Tool
gavel

Privacy & Legal Disclaimer

1. Client-Side Browser Processing

All utility tools on DeepEngineerHub (including Image to PDF, Text Formatters, JSON Converters, and Encryptors) execute 100% locally within your client browser using WebAssembly and JavaScript. No uploaded images, text, or documents are transmitted, collected, or stored on remote servers.

2. Limitation of Liability ("As-Is" Provision)

Tools and services are provided free of charge for convenience and educational purposes "as-is" without warranties of any kind. DeepEngineerHub shall not be held liable for any data loss, formatting inconsistencies, or indirect damages resulting from tool usage.

3. Open Source & Third-Party Software

Certain utilities utilize open-source client libraries (such as jsPDF, Mermaid.js, Pyodide) licensed under MIT, Apache, or BSD open licenses. All intellectual property remains with their respective copyright holders.